package com.tbit.uqbike.service.business.impl;

import com.github.pagehelper.PageHelper;
import com.tbit.uqbike.enums.SystemCodeEnum;
import com.tbit.uqbike.manager.exception.BaseException;
import com.tbit.uqbike.object.pojo.AccountSmsModel;
import com.tbit.uqbike.service.business.AccountSmsModelService;
import com.tbit.uqbike.webmanager.dao.core.AccountSmsModelDao;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * 短信模板(Accountsmsmodel)表服务实现类
 *
 * @author makejava
 * @since 2020-11-17 18:00:36
 */
@Service("accountsmsmodelService")
public class AccountSmsModelServiceImpl implements AccountSmsModelService {
    @Resource
    private AccountSmsModelDao accountsmsmodelDao;

    /**
     * 通过ID查询单条数据
     *
     * @return 实例对象
     */
    @Override
    public AccountSmsModel queryById(AccountSmsModel accountsmsmodel) {
        return this.accountsmsmodelDao.queryById(accountsmsmodel);
    }

    /**
     * 查询多条数据
     *
     * @param accountsmsmodel
     * @return 对象列表
     */
    @Override
    public List<AccountSmsModel> queryAllByLimit(AccountSmsModel accountsmsmodel) {
        PageHelper.startPage(accountsmsmodel.getPage().getPageNO(), accountsmsmodel.getPage().getRowCount());
        return this.accountsmsmodelDao.queryAllByLimit(accountsmsmodel);
    }

    /**
     * 新增数据
     *
     * @param accountsmsmodel 实例对象
     * @return 实例对象
     */
    @Override
    public AccountSmsModel insert(AccountSmsModel accountsmsmodel) {
        if (null != accountsmsmodelDao.queryById(accountsmsmodel)) {
            throw new BaseException(SystemCodeEnum.SMSMODELID_HAVE_EXIST);
        }
        accountsmsmodel.setUpdateTime(new Date());
        this.accountsmsmodelDao.insert(accountsmsmodel);
        return accountsmsmodel;
    }

    /**
     * 修改数据
     *
     * @param accountsmsmodel 实例对象
     * @return 实例对象
     */
    @Override
    public AccountSmsModel update(AccountSmsModel accountsmsmodel) {
        accountsmsmodel.setUpdateTime(new Date());
        this.accountsmsmodelDao.update(accountsmsmodel);
        return this.queryById(accountsmsmodel);
    }

    /**
     * 通过主键删除数据
     *
     * @return 是否成功
     */
    @Override
    public boolean deleteById(AccountSmsModel accountsmsmodel) {
        return this.accountsmsmodelDao.deleteById(accountsmsmodel) > 0;
    }
}